<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="/lib/layui/css/layui.css" rel="stylesheet"/>
    <link href="/css/common.css" rel="stylesheet"/>
    <title>重置密码</title>
    <style>
        html, body {
            height: 100%
        }
    </style>
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;padding: 170px 0;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="mobile"></label>
                <input type="text" name="mobile" id="mobile" lay-verify="phone" placeholder="请输入手机号" class="layui-input" autocomplete="off">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="smsCode"></label>
                        <input type="text" name="smsCode" id="smsCode" lay-verify="required" placeholder="短信验证码" class="layui-input" autocomplete="off">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="getSmsCode">获取验证码</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="password"></label>
                <input type="password" name="password" id="password" lay-verify="required|password" placeholder="密码（6~8位字母和数字）" class="layui-input"
                       autocomplete="off">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="passwordAgain"></label>
                <input type="password" name="passwordAgain" id="passwordAgain" lay-verify="required|password" placeholder="确认密码（6~8位字母和数字）" class="layui-input"
                       autocomplete="off">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="resetSubmit">重置密码</button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <a href="/login.html" class="layadmin-user-jump-change layadmin-link layui-hide-xs">帐号已注册，直接登录</a>
            </div>
        </div>
    </div>
</div>
<script src="/lib/layui/layui.all.js" charset="utf-8"></script>
<script src="/script/common.js" charset="utf-8"></script>
<script>
    layui.$('#LAY-user-login').attr('style', 'padding:' + (document.body.clientHeight - 358) / 2 + 'px 0;');
    layui.use(['baseUtil'], function () {
        var $ = layui.jquery,
            form = layui.form,
            baseUtil = layui.baseUtil;

        $('#getSmsCode').bind('click', function () {
            var mobile = $('#mobile').val();
            var reg = /^[1][3,4,5,7,8][0-9]{9}$/;
            if (!reg.test(mobile)) {
                baseUtil.msg('请输入正确的手机号');
                return false;
            }
            baseUtil.doPost('/system/confirm/getSmsCode.do', { mobile: mobile }, function (result) {
                baseUtil.msg(result.msg);
                if (result.code === 0) {
                    var totalTime = 60;
                    $('#getSmsCode').addClass('layui-btn-disabled').attr('disabled', true);
                    $('#getSmsCode')[0].innerHTML = totalTime + '秒后重获';
                    var index = window.setInterval(function () {
                        totalTime--;
                        if (totalTime < 1) {
                            window.clearInterval(index);
                            $('#getSmsCode').removeClass('layui-btn-disabled').attr('disabled', false);
                            $('#getSmsCode')[0].innerHTML = '获取验证码';
                        } else {
                            $('#getSmsCode')[0].innerHTML = totalTime + '秒后重获';
                        }
                    }, 1000)
                }
            });
        });

        form.verify({
            password: function (value) {
                var reg = /^[0-9a-zA-Z]{6,8}$/;
                if (!reg.test(value)) {
                    return '密码格式不正确';
                }
            }
        });

        form.on('submit(resetSubmit)', function (data) {
            var password = $('#password').val();
            var passwordAgain = $('#passwordAgain').val();
            if (password !== passwordAgain) {
                baseUtil.msg('两次密码输入不一致');
                return false;
            }
            baseUtil.doPost('/system/confirm/reset.do', data.field, function (result) {
                if (result.code === 0) {
                    baseUtil.alert(result.msg, '1', function () {
                        window.location.href = '/login.html';
                    });
                } else {
                    baseUtil.msg(result.msg);
                }
            });
        });
    });
</script>
</body>
</html>
